package Thread;


import java.util.Random;
import java.util.concurrent.BlockingDeque;
import java.util.concurrent.LinkedBlockingDeque;

public class demo1 {

    public static void main(String[] args) throws InterruptedException {
        BlockingDeque<Integer> queue = new LinkedBlockingDeque<>(1000);
       Thread  Consumer = new Thread(()->{
            while(true){
               try {
                    int num = 0;
                   num = queue.take();
                    System.out.println("消费元素："+num);
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
               }
            }
       });

      Consumer.start();

        Thread Productor = new Thread(()->{
            int i = 0;
            while (true){
                    try {
                        int val = i;
                        queue.put(val);
                        i++;
                        System.out.println("生产元素："+val);

                    } catch (InterruptedException e) {
                        e.printStackTrace();

                    }
        }
        });
        Productor.start();

        Consumer.join();
        Productor.join();

    }
}
